package fun.wxy.camera;

import android.os.Bundle;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import fun.wxy.camera.fragment.IrCameraFragment;
import fun.wxy.camera.fragment.NfcReadFragment;
import fun.wxy.camera.fragment.PalmFragment;
import fun.wxy.camera.fragment.RgbCameraFragment;
import fun.wxy.camera.fragment.UsbDevicesFragment;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);

        // 初始化按钮并设置点击监听器
        Button viewUsbDeviceBtn = findViewById(R.id.view_usb);
        viewUsbDeviceBtn.setOnClickListener(v -> {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.main, new UsbDevicesFragment())
                    .addToBackStack("main")
                    .commit();
        });

        Button viewRgbCameraBtn = findViewById(R.id.view_camera_rgb);
        viewRgbCameraBtn.setOnClickListener(v -> {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.main, new RgbCameraFragment())
                    .addToBackStack("main")
                    .commit();
        });

        Button viewIrCameraBtn = findViewById(R.id.view_camera_ir);
        viewIrCameraBtn.setOnClickListener(v -> {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.main, new IrCameraFragment())
                    .addToBackStack("main")
                    .commit();
        });

        Button readNfcBtn = findViewById(R.id.read_nfc);
        readNfcBtn.setOnClickListener(v -> {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.main, new NfcReadFragment())
                    .addToBackStack("main")
                    .commit();
        });

        Button readPalmBtn = findViewById(R.id.palm_read);
        readPalmBtn.setOnClickListener(v -> {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.main, new PalmFragment())
                    .addToBackStack("main")
                    .commit();
        });

        // 处理窗口边距
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
    }
}